import { createApp } from 'vue';
import { createPinia } from 'pinia';
import createPersistedState from '@/config/pania_store/plugins/persistedPlugin';

declare module 'pinia' {
  export interface PiniaCustomProperties {
    appInstance: ReturnType<typeof createApp>
  }
}

/**
 * 安装pinia插件
 * @param app 要安装的vue应用
 */
function installPinia (app: ReturnType<typeof createApp>) {
  const pinia = createPinia();
  pinia.use((context) => {
    context.store.appInstance = app;
  });
  pinia.use(createPersistedState({
    notPersistedStateIds: []
  }));
  app.use(pinia);
}

export default installPinia;
